<?php
if ( ! defined( 'MEDIAWIKI' ) )
	die();
 
$wgExtensionCredits['other'][] = array(
	'name' => 'AccessBasedPersonalUrls',
	'description' => 'Show access based urls list in Personal bar (list is greatly reduced)',
);
 
$wgExtAddPersonalUrls = new ExtAddPersonalUrls();
 
$wgHooks['PersonalUrls'][] = array( &$wgExtAddPersonalUrls, 
																		'onAddPersonalUrls' );
class ExtAddPersonalUrls {
	public static $mAnon =
		array ( 
			array( 
				'page' => 'Special:UserLogin',
				'name' => 'Войти',
				'args' => null 
			) 
		);
 
	public static $mUser =
		array (
			array( 
				'page' => null,
				'name' => '$username',
				'args' => null 
			),
			array(
				'page' => 'Special:FormEdit/Print_media_edit',
				'name' => 'Новое печатное СМИ',
				'args' => null
			),
			array(
				'page' => 'Special:FormEdit/Online_media_edit',
				'name' => 'Новое онлайн СМИ',
				'args' => null
			),
			array(
				'page' => 'Special:FormEdit/Agency_media_edit',
				'name' => 'Новое агентство',
				'args' => null
			),
			array(
				'page' => 'Special:Watchlist',
				'name' => 'Комментарии',
				'args' => null
			),
			array(
				'page' => 'User_talk:$username',
				'name' => 'Переписка',
				'args' => null
			),
			array(
				'page' => 'Special:UserLogout',
				'name' => 'Выйти',
				'args' => null
			)
		);
 
	public static $mSysop =
		array (
			array(
				'page' => null,
				'name' => '$username',
				'args' => null
			),
			array(
				'page' => 'Special:Watchlist',
				'name' => 'Комментарии',
				'args' => null
			),
			array(
				'page' => 'Special:RunQuery/Print_spam_search_form',
				'name' => 'Массовая рассылка',
				'args' => null
			),
			array(
				'page' => 'Special:UnreviewedPages',
				'name' => 'Непроверенные страницы',
				'args' => null
			),
			array(
				'page' => 'Special:UserLogout',
				'name' => 'Выйти',
				'args' => null
			),
		);

	
	function onAddPersonalUrls( &$personal_urls, &$wgTitle ) {
		global $wgUser;
		$pages = (($wgUser->isAnon())?self::$mAnon:((!array_intersect(array('sysop'), $wgUser->getGroups()))?self::$mUser:self::$mSysop));
		$username = $wgUser->getName();
		$pageurl = $wgTitle->getLocalURL();
		$personal_urls = array();
 
		foreach( $pages as $item ) {
			$urldetails = Skin::makeUrlDetails( str_replace( '$username', $username, $item['page'] ) );
			$args = str_replace( '$username', $username, $item['args'] );
			$name = str_replace( '$username', $username, $item['name'] );

			$personal_urls[] = array(
				'text' => $name,
				'href' => $urldetails['href'] . $args,
				'class' => $args ? false : ($urldetails['exists'] ? false : 'new'),
				'active' => $args ? false  : ($urldetails['href'] == $pageurl)
			);
		}

		return true;
	}
}
